/**
 * Created by levy on 2018/2/12.
 */
import Vue from 'vue';
import ElementUI, { Notification, Message, MessageBox } from 'element-ui';
import ElFormRenderer from '@femessage/el-form-renderer';
import ElDataTable from '@femessage/el-data-table'
import '../theme/index.css';
import IconFont from '../components/iconFont';
import VueClipboard from 'vue-clipboard2';
import { Editable, EditableColumn } from 'vue-element-extends';
import MUpload from '../components/m-upload';

Vue.use(ElementUI);
// 兼顾saas项目使用size: 'medium'，否则这个页面样式错乱，后期优化掉http://localhost:3004/#/cso/serviceProvider/promotionAnd/added
if(process.env.PROJECT_NAME === 'M_SAAS'){
  Vue.prototype.$ELEMENT = { size: 'medium' };
}
Vue.use(VueClipboard);
Vue.component('el-form-renderer', ElFormRenderer);
Vue.component('IconFont', IconFont);
Vue.component('el-data-table', ElDataTable)
Vue.component('m-upload', MUpload);
Vue.component('ElxEditable', Editable)
Vue.component('ElxEditableColumn', EditableColumn)
// 封装默认class
const notify = option => Notification(Object.assign({ customClass: 'notify_class' }, option));
const $message = option => Message(Object.assign({ customClass: 'notify_class' }, option));
const optionsBox = (options, type) => {
  if (typeof options === 'string') {
    options = { message: options };
  }
  options.type = type;
  return options;
};
let typeArr = ['success', 'warning', 'info', 'error'];
Object.keys(Notification).forEach(type => {
  if (typeArr.includes(type)) {
    notify[type] = options => notify(optionsBox(options, type));
    $message[type] = options => $message(optionsBox(options, type));
  } else {
    notify[type] = Notification[type];
    $message[type] = Message[type];
  }
});

Vue.prototype.$notify = notify;
Vue.$notify = notify;

Vue.prototype.$msgbox = MessageBox;
Vue.prototype.$alert = MessageBox.alert;
Vue.prototype.$confirm = MessageBox.confirm;
Vue.prototype.$prompt = MessageBox.prompt;
Vue.prototype.$message = $message;
